home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / ListItemView.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  4.1 KB  |  107 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.Rectangle;
  9. import java.awt.Shape;
  10. import java.awt.Toolkit;
  11. import java.awt.image.ImageObserver;
  12.  
  13. public class ListItemView extends View {
  14.    int m_bulletRadius = 6;
  15.    int m_bulletXPos;
  16.    static Image m_bulletImg;
  17.    static boolean m_bHavePixels;
  18.    static boolean m_bImageLoadFailed;
  19.    int m_orderNum = -1;
  20.  
  21.    public ListItemView(View parent, Element e, HTMLPane container) {
  22.       super(parent, e, container);
  23.    }
  24.  
  25.    protected int getPreferredSpan(int axis) {
  26.       return axis == 1 ? super.getPreferredSpan(1) : 0;
  27.    }
  28.  
  29.    protected void init() {
  30.       if (super.m_elem.getType() != 25) {
  31.          ((View)this).setInsets(0, this.m_bulletRadius + 20, 0, 0);
  32.       }
  33.  
  34.       if (!m_bImageLoadFailed && !m_bHavePixels) {
  35.          m_bulletImg = Utilities.loadImage(super.m_container, "horst\\icons\\bullet.gif");
  36.          if (m_bulletImg == null) {
  37.             m_bImageLoadFailed = true;
  38.          } else {
  39.             m_bHavePixels = true;
  40.          }
  41.       }
  42.  
  43.    }
  44.  
  45.    protected boolean isNewlineView() {
  46.       return true;
  47.    }
  48.  
  49.    protected boolean isWrappable() {
  50.       return true;
  51.    }
  52.  
  53.    protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
  54.       Rectangle b = super.layout(x, y, width, info);
  55.       this.m_bulletXPos = b.x;
  56.       if (super.m_children.length > 0 && super.m_children[0].m_bounds.x > x + super.m_insets.left) {
  57.          this.m_bulletXPos = super.m_children[0].m_bounds.x - super.m_insets.left;
  58.       }
  59.  
  60.       return b;
  61.    }
  62.  
  63.    protected void move(int x, int y, boolean bMoveFloaters) {
  64.       super.move(x, y, bMoveFloaters);
  65.       this.m_bulletXPos += x;
  66.    }
  67.  
  68.    public void paint(Graphics g, Shape alloc) {
  69.       super.paint(g, alloc);
  70.       this.paintInset(g);
  71.       ((View)this).drawDebugBox(g, Color.blue);
  72.    }
  73.  
  74.    protected void paintInset(Graphics g) {
  75.       if (super.m_elem.getType() == 27) {
  76.          if (this.m_orderNum > 0) {
  77.             Font f = ((View)this).getFont();
  78.             FontMetrics fmetrics = Toolkit.getDefaultToolkit().getFontMetrics(f);
  79.             Font oldFont = g.getFont();
  80.             g.setFont(f);
  81.             g.setColor(Color.black);
  82.             g.drawString(this.m_orderNum + ".", this.m_bulletXPos, super.m_bounds.y + fmetrics.getHeight() - fmetrics.getDescent());
  83.             g.setFont(oldFont);
  84.          } else if (m_bHavePixels) {
  85.             int imgHeight = m_bulletImg.getHeight((ImageObserver)null);
  86.             int h = Toolkit.getDefaultToolkit().getFontMetrics(((View)this).getFont()).getHeight();
  87.             int y = Math.max(0, h - imgHeight) / 2 + super.m_bounds.y;
  88.             g.drawImage(m_bulletImg, this.m_bulletXPos + super.m_insets.left / 2 - this.m_bulletRadius / 2, y, (ImageObserver)null);
  89.          } else {
  90.             int h = Toolkit.getDefaultToolkit().getFontMetrics(((View)this).getFont()).getHeight();
  91.             int y = Math.max(0, h - this.m_bulletRadius) / 2 + super.m_bounds.y;
  92.             g.setColor(Color.black);
  93.             g.fillOval(this.m_bulletXPos + super.m_insets.left / 2 - this.m_bulletRadius / 2, y, this.m_bulletRadius, this.m_bulletRadius);
  94.          }
  95.       }
  96.  
  97.    }
  98.  
  99.    protected void setLeftInset(int val) {
  100.       super.m_insets.left = val;
  101.    }
  102.  
  103.    protected void setOrderNumber(int orderNum) {
  104.       this.m_orderNum = orderNum;
  105.    }
  106. }
  107.